package com.JZ.QM.service.impl;

import com.JZ.QM.service.UserAccountService;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.JZ.QM.common.utils.PageUtils;
import com.JZ.QM.common.utils.Query;

import com.JZ.QM.common.dao.UserAccountDao;
import com.JZ.QM.common.entity.UserAccountEntity;

import javax.annotation.Resource;


@Service
public class UserAccountServiceImpl extends ServiceImpl<UserAccountDao, UserAccountEntity> implements UserAccountService {

    @Resource
    UserAccountDao userAccountDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) throws Exception {
        IPage<UserAccountEntity> page = this.page(
                new Query<UserAccountEntity>().getPage(params),
                new QueryWrapper<UserAccountEntity>()
        );

        return new PageUtils(page);
    }

    /**
     * 查询账户余额
     * @param userId
     * @return
     */
    @Override
    public UserAccountEntity quaryByUserId(Long userId) {
        //构造查询器
        QueryWrapper<UserAccountEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id",userId);

        UserAccountEntity userAccountEntity = userAccountDao.selectOne(queryWrapper);

        return userAccountEntity;
    }

    /**
     * 通过用户id获取用户的账号id
     * @param userId 用户id
     * @return
     */
    @Override
    public UserAccountEntity getAccount(Long userId) {
        //条件构造器
        QueryWrapper queryWrapper=new QueryWrapper();
        //账户基本信息
        UserAccountEntity userAccountEntity=new UserAccountEntity();

        queryWrapper.eq("user_id",userId);
        //获取账户的id
        userAccountEntity=userAccountDao.selectOne(queryWrapper);
        return userAccountEntity;
    }
}